![]() Acrobat file (179K) |
![]() ClarisWorks 4 file (39K) |
![]() not available yet |
Technote 1064 |
September 1996 |
By Albert Hui
Apple Developer Technical Support (DTS)
While you can set the Daylight Savings Time state from the Date & Time Control Panel and determine what the state is by checking the checkbox in the Control Panel, you can also figure out the state from within your program. This Technote shows you how.
Inside Macintosh: Operating System Utilities, Chapter 4, does not directly explain how you can find out if daylight savings time is in effect. With the MachineLocation data structure dlsDelta field, you can find out how the time would have changed, but the field does not tell you whether daylight savings time is in effect.
This Technote is at aimed at Macintosh developers who must deal with date and time programming issues.
The top byte of the gmtDelta should be masked off and preserved when writing: it's reserved for future extension. The gmtDelta is really a 3-byte value, so you must take care to get and set it properly, as in the following C code examples:
#includelong GetGmtDelta(MachineLocation myLocation) { long internalGMTDelta; internalGMTDelta = myLocation.gmtDelta & 0x00ffffff; if ( (internalGMTDelta >> 23) & 1 ) // need to sign extend internalGmtDelta = internalGmtDelta | 0xff000000; return (internalGmtDelta); } void SetGmtDelta(MachineLocation *myLocation, long myGmtDelta) { char tempSignedByte; tempSignedByte = myLocation->dlsDelta; // save away high byte myLocation->gmtDelta = myGmtDelta; // make sure not overwritten myLocation->dlsDelta = tempSignedByte; // restore high byte }
#includeVersions of the Date & Time Control Panel greater than 7.1 set the high bit of the high byte if Daylight Savings is checked "on" in the CDEV. The Map CDEF has not yet been revised to use this field. Future versions of Map or Date & Time may use the byte differently, so be sure to use it with caution.int IsDaylightSavingsOn() { int retVal = 0; MachineLocation theLocation; ReadLocation(&theLocation); if (theLocation.u.dlsDelta == (signed char) 0x80) { retVal = 1; } return(retVal); }